package com.jml.装饰模式实现三级缓存.decorator.impl;


import com.jml.装饰模式实现三级缓存.component.ComponentCache;
import com.jml.装饰模式实现三级缓存.decorator.AbstractDecorator;
import java.util.HashMap;
import java.util.Map;

/**
 * @author:jml
 * @date: 2019/9/9 14:09
 * @description：
 */
public class TwoRedisDecorator extends AbstractDecorator {

    Map twoRedisCacheMap = new HashMap<>();

    public TwoRedisDecorator(ComponentCache baseCacheComponent) {
        super(baseCacheComponent);
    }


    @Override
    public Object getCache(String key) {
        System.out.println(">>>调用二级缓存查询");
        //1.先查二级缓存，如果没有就查一级
        Object twoValue = twoRedisCacheMap.get(key);
        if (twoValue == null) {
            //查一级缓存
            Object oneValue = super.getCache(key);
            if (oneValue != null) {
                twoRedisCacheMap.put(key, oneValue);
                twoValue = oneValue;
            }
        }
        return twoValue;
    }

    @Override
    public void putCache(String key, Object value) {
    }

}
